const xq = 'https://vue3antdv-7gcma6b228a5b287-1256680780.tcloudbaseapp.com/api/v2/'
const bq = 'https://vue3antdv-7gcma6b228a5b287-1256680780.tcloudbaseapp.com/api/v2/'
const dp = 'https://vue3antdv-7gcma6b228a5b287-1256680780.tcloudbaseapp.com/api/v2/'
const count=5
Page({
    data:{
        start:0,
        type:' ',
        id:' '
    },
    onLoad(option){
        console.log(option)
        let {type,id} = option
            this.setData({
                type,id
            })
        wx.request({
          url: xq+option.type+'/'+option.id,
          success:res=>{
              console.log({xq:res.data})
              let mygenres = res.data.genres.join('/')
              let myactors = res.data.actors.slice(0,3).map(v=>{
                  return v.name
              }).join('/')
              let rate = res.data.rratin.value
              //console.log(rate)
              //星星个数
              let lights = 'a'.repeat(Math.floor(rate / 2))
              //半个星星个数
              let halfs = rate % 2 != 0
              //灰色星星个数
              let grays = 'a'.repeat(Math.floor((10 - rate) / 2))
              let rateText = rate && rate > 0 ? rate.toFixed(1) : "未评分"
              this.setData({
                  xq:res.data,
                  myactors,
                  mygenres,
                  rateText: rateText,
                  lights: lights,
                  halfs: halfs,
                  grays: grays
              })
          }
        })
        wx.request({
          url: bq+option.type+'/'+option.id+'/tags?count=5',
          success:res=>{
            //   console.log({vvv:vvv})
              let bq = res.data.ttag
            let vvv = bq.splice(14,5)
            console.log({bq:vvv})
              this.setData({bq:vvv})
          }
        })
        wx.request({
          url: dp+option.type+'/'+option.id+'/interests?count=5',
          success:res=>{
            console.log({dp:res.data})
              this.setData({dp:res.data})
          }
        })
    },
    onReachBottom(){
        this.setData({
            start:this.data.start+count
        })
        let url = dp + this.data.type+'/'+this.data.id+'/interests?start='+this.data.start+'&count='+count
        console.log(url)
        wx.request({
          url,
          success:res=>{
              console.log(res)
              let dp = this.data.dp
              let ttt = dp.interests
              console.log(ttt)
              let sss = res.data.interests
              console.log(sss)
              ttt = ttt.concat(sss)
              dp.interests=ttt
              this.setData({
                  dp
              })
          }
        })
    },
    stars: function () {
        let that = this //定义全局变量
        let rate = that.properties.rate
        //console.log(rate)
        //星星个数
        let lights = 'a'.repeat(Math.floor(rate / 2))
        //半个星星个数
        let halfs = rate % 2 != 0
        //灰色星星个数
        let grays = 'a'.repeat(Math.floor((10 - rate) / 2))
        let rateText = rate && rate > 0 ? rate.toFixed(1) : "未评分"
        that.setData({
            rateText: rateText,
            lights: lights,
            halfs: halfs,
            grays: grays
        })
    },
})